'use strict'

var nunjuck = require('nunjucks');

function createEnv(path,opts){
    path = path || 'views';
    opts = opts || {};
    var envOptions = {
        autoescape:opts.autoescape || true,
        watch:opts.noCache || true
        
    }
    var env = nunjuck.configure('views',envOptions);
    return env;
}

module.exports = async (ctx,next)=>{
    var env = createEnv();
    ctx.render = function(views,model){
        ctx.body = env.render(views,model);
    }
    await next();
}